package org.game.module.event.listener;

import org.constant.EventConditionKey;
import org.constant.EventConditionType;
import org.constant.EventType;
import org.game.db.bean.Player;
import org.game.plugin.event.GameEvent;
import org.game.plugin.event.GameEventListener;
import org.game.plugin.event.GameEventStack;
import org.game.plugin.event.GameEventType;

import com.sojoys.artifact.tools.ToolMap;

/**
 * @author : DengYing
 * @CreateDate : 2018年1月11日 下午2:59:44
 * @Description ：玩家数据变更监听
 */
@GameEventType(EventType.PLAYER_CHANGE)
public class PlayerChangeEventListenner implements GameEventListener {

	@Override
	public void onEvent(GameEvent event) {
		GameEventStack eventStack = event.peek();
		switch (eventStack.getConditionType()) {
		// 玩家升级到X级
		case EventConditionType.PLAYER_LVL: {
			if(checkTriggerType(event.getIn(), eventStack.getConditionType())){
				int oldLv = ToolMap.getInt(EventConditionKey.OLD_LEVEL, event.getIn());
				int nowLv = ToolMap.getInt(EventConditionKey.NOW_LEVEL, event.getIn());
				int progress = eventStack.getMaxProgress();
				if (oldLv < progress) {
					eventStack.setProgress(nowLv);
				}
			}
			break;
		}
		case EventConditionType.CHANGE_PLAYER_NAME: {
			if(checkTriggerType(event.getIn(), eventStack.getConditionType())){
				eventStack.changeProgress(1);
			}
			break;
		}
		default:
			break;
		}
	}

	@Override
	public void initEventCondition(Player player, GameEventStack eventStack) {
		switch (eventStack.getConditionType()) {
		// 玩家升级到X级
		case EventConditionType.PLAYER_LVL:{
			int plv = player.getLevel();
			eventStack.setProgress(plv);
		}
			break;
		default:
			break;
		}
	}

}
